/**
 * 
 */
package co.fitstart.mobile.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.service.impl.GenericServiceImpl;
import com.demo2do.core.support.Page;

import co.fitstart.entity.credit.product.CreditProduct;
import co.fitstart.entity.credit.product.CreditProductTag;
import co.fitstart.mobile.dao.support.CreditProductDaoSupport;
import co.fitstart.mobile.service.CreditProductService;

/**
 * @author Guangli Yan
 *
 */
@Service("creditProductService")
public class CreditProductServiceImpl extends GenericServiceImpl<CreditProduct> implements CreditProductService{

	@Autowired
	private CreditProductDaoSupport creditProductDaoSupport;
	
	/* (non-Javadoc)
	 * @see co.fitstart.mobile.service.CreditProductService#list(co.fitstart.entity.credit.product.CreditProductTag, com.demo2do.core.support.Page)
	 */
	public List<CreditProduct> list(CreditProductTag tag, Page page) {

		List<CreditProduct> creditProducts = creditProductDaoSupport.list(tag, page.getBeginIndex(), page.getMaxResultRecords());
		
		page.calculate(creditProducts.size());
		
		return creditProducts.size() > page.getEveryPage() ? creditProducts.subList(0, page.getEveryPage()) : creditProducts;
	}

}
